import 'package:flutter/material.dart';

class WidgetPlayerProgressDiv extends StatefulWidget {
  const WidgetPlayerProgressDiv(
      {super.key, required Map<int, int> srtsOkMap, required this.i, required int curIndex, required this.onTap})
      : srtsOkMap = srtsOkMap,
        curIndex = curIndex;

  final Map<int, int> srtsOkMap;
  final int i;
  final int curIndex;
  final VoidCallback onTap;

  @override
  State<WidgetPlayerProgressDiv> createState() => WidgetPlayerProgressDivState();
}

class WidgetPlayerProgressDivState extends State<WidgetPlayerProgressDiv> {
  bool _divTapDownStatus = false;
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        onTap: () {
          // jumpTo(i);
          widget.onTap();
        },
        onTapDown: (TapDownDetails d) {
          // print("按下");
          setState(() {
            _divTapDownStatus = true;
          });
          Future.delayed(Duration(seconds: 1), () {
            if (_divTapDownStatus) {
              setState(() {
                _divTapDownStatus = false;
              });
            }
          });
        },
        onTapUp: (TapUpDetails d) {
          // print("抬起");
          if (_divTapDownStatus) {
            setState(() {
              _divTapDownStatus = false;
            });
          }
        },
        onTapCancel: () {
          setState(() {
            _divTapDownStatus = false;
          });
        },
        child: Container(
          height: 28.0,
          color: _divTapDownStatus ? Colors.blue : (widget.srtsOkMap[widget.i] == null ? Colors.grey : Colors.green),
          margin: EdgeInsets.all(2),
          alignment: Alignment.center,
          child: Container(
              alignment: Alignment.center,
              width: 20,
              color: _divTapDownStatus
                  ? Colors.blue
                  : (widget.curIndex == widget.i
                      ? Colors.red
                      : (widget.srtsOkMap[widget.i] == null ? Colors.grey : Colors.green)),
              child: Text(
                "${widget.i + 1}",
                style: TextStyle(color: Colors.white, fontSize: 8),
              )),
        ));
  }
}
